<template>
  <div>
    <div id="demo1"
         :editorData="editorData">
      <!-- <template v-if="description">{{ description }}</template> -->

    </div>
  </div>
</template>

<script>
import wangEditor from 'wangeditor'
export default {
  props: {
    description: String
  },
  data() {
    return {
      editor: null,
      editorData: ''
    }
  },
  mounted() {
    const editor = new wangEditor('#demo1')

    editor.config.onchange = (newHtml) => {
      this.editorData = newHtml
      this.$emit('editorData', newHtml)
    }
    editor.config.onchangeTimeout = 500
    editor.create()
    if (this.description !== '') {
      console.log(this.description)
    }

    this.editor = editor
  },
  methods: {
    getEditorData() {
      // 获取编辑器的内容
      const data = this.editor.txt.html()
      alert(data)
    },
    beforeDestroy() {
      // 调用销毁 API 对当前编辑器实例进行销毁
      this.editor.destroy()
      this.editor = null
    }
  }
}
</script>

<style>
</style>
